<template>
    <div style="display: flex;line-height: 60px">
        <div style="margin-top: 8px">
            <i :class="icon" style="font-size: 20px" @click="collapse"></i>
        </div>

        <div style="flex: 1;text-align: center;font-size: 25px ">
            <span style="padding-right: 8px">
                <img src="../assets/logo.jpg" width="50px" height="50px" style="border-radius: 10px;margin-top: 5px">
            </span>
            <span style="font-family: SimSun;color: white;vertical-align:12px">欢迎使用云医疗系统</span>
        </div>
        <el-dropdown style="color: white" >
            <el-avatar :src="userinfo.picture" style="vertical-align:-12px;margin-right: 5px"></el-avatar>
            <span>{{userinfo.userName}}</span> <i class="el-icon-arrow-down"style="margin-left: 5px"></i>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="toUser">个人中心</el-dropdown-item>
                <el-dropdown-item @click.native="toPassword">修改密码</el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>

    </div>
</template>

<script>
    import qs from "qs";

    export default {
        name: "Header",
        props:{
            icon:String
        },
        data(){
            return{
                //当前用户的信息
                userinfo:{},
            }
        },
        methods:{
            //查询用户信息
            initUserInfo(){
                this.$axios.get("system/api/user/info").then(r=>{
                    this.userinfo=r.data.t;
                })
            },
            //个人中心
            toUser(){
                this.$router.push("/userCenter");
            },
            //修改密码
            toPassword(){
                this.$router.push("/updUserPassword");
            },
            //退出登录
            logout(){
                this.$confirm('您确定要退出登录吗？, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$axios.get("system/api/user/logout").then(r=>{
                        if (r.data.t){
                            this.$message.success("退出成功");
                            sessionStorage.clear();
                            this.$router.push("/login");
                        }else {
                            this.$message.error("退出失败");
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            },
            collapse(){
                this.$emit('doCollapse')
            }
        },
        created() {
            this.initUserInfo();
        }

    }
</script>

<style scoped>

</style>
